using System.Security.Principal;
using System.Threading;
using MbUnit.Framework;
using EnterpriseLibraryContrib.PostSharp4EntLib.PolicyInjection;

namespace EnterpriseLibraryContrib.PostSharp4EntLib.Test.PolicyInjection.AttributeDrivenPolicies
{
        [TestFixture]
    public class Authorization
    {
        public Authorization()
        {
        }

        [TestFixtureSetUp]
        public void SetUp()
        {
            IPrincipal principal = new GenericPrincipal(new GenericIdentity("test"), new string[] {"Employee"});
            Thread.CurrentPrincipal = principal;
        }

        [AuthorizationCallHandler("IsEmployee", ProviderName = "RuleProvider")]
        private void Authorized()
        {
        }

        [Test]
        public void TestAuthorized()
        {
            this.Authorized();
        }

        [AuthorizationCallHandler("IsManager")]
        private void NotAuthorized()
        {
        }

        [Test]
        [ExpectedException(typeof (Exception))]
        public void TestNotAuthorized()
        {
            this.NotAuthorized();
        }
    }
}